package com.tuling.cloud.study;

import com.tuling.cloud.study.feign.OrderFeignClient;
import com.tuling.cloud.study.feign.UserFeignClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class AggregationController2 {

  public static final Logger LOGGER = LoggerFactory.getLogger(ZuulApplication.class);

  @Autowired
  private OrderFeignClient orderFeignClient;

  @Autowired
  private UserFeignClient userFeignClient;
	
  @GetMapping("/aggregate2/{id}")
  public Map<String, User> findById(@PathVariable Long id) throws Exception {
	  Map<String, User> dataMap = new HashMap<>();
	  User user = userFeignClient.findByIdFromUserService(id);
	  User orderUser = orderFeignClient.findByIdFromOrderService(id);
	  dataMap.put("user", user);
	  dataMap.put("orderUser", orderUser);
	  return dataMap;
  }
}